<!DOCTYPE html>
<html>
<head>
    <head/>
    <title>选择医院</title>
    <titleType style="display: none;">yygh</titleType>
    <%- include('../../../_global/baseLibs') %>
    <script src="/static/lib/forweb.js"></script>
    <script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
    <link rel="stylesheet" href="/static/css/qyjm/page.css"/>
</head>
<style>
    body {
        background: #fbfafa;
    }

    .filtrate-box li {
        border-bottom: 1px solid #DDDDDD;
    }

    .yygh-box .filtrate-sub-check {
        top: 3.625rem;
    }

    .search input {
        width: 94%;
        height: 2.4rem;
        border-radius: 5px;
        border: none;
        background: #f1f1f1;
        margin: .5rem 3%;
        font-size: 1.2rem;
        text-indent: .2rem;
        text-align: center;
    }

    .search input:focus {
        outline: none;
    }
</style>

<body>
<section class="page-wrap yygh-box">
    <header class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0);"><i class="iconfont icon-back"></i></a>
            </div>
            <!-- <div class="right-tool">
                <a href="#"><i class="fdj-black-icon"></i></a>
            </div> -->
            <div class="title">选择医院</div>
        </div>
    </header>


    <div class="search">
        <form action="javascript:;" >
            <input placeholder="搜索医院" type="search"
                   id="queryInput">
        </form>

    </div>

    <div class="doctor-list-box" id="hosDiv" style="margin-top:0;">
        <ul id="hosUl">

        </ul>
    </div>
</section>
</body>
<script type="text/html" id="xzqhLi">
    <li><a href="javascript:void(0);">离我最近</a></li>
</script>
<script type="text/html" id="hosLi">
    <li>
        <a href="javascript:void(0);">
            <i class="hospital-icon hosImgUrl"></i>
            <div class="text-box">
                <p>
                    <span class="title-text hosName"></span>
                    <span class="yellow-text hosLevel"></span>
                    <span class="yellow-text isMedicare"></span>
                </p>
                <p>
                    <span class="doctorCount"></span>
                    <span class="gray-text distance"></span>
                </p>
            </div>
            <div class="item-after"><i class="iconfont icon-more"></i></div>
        </a>
    </li>
</script>
<script type="text/javascript">
    var requestRoot = "/jkcsHt/yygh";
    var t1;


    function toKslb(hos) {

        StoreCache.setCache("findHos", hos);
        var fromName = $.QuickUrlUtils.getRequest("name");
        var fromUrl = $.QuickUrlUtils.getRequest("from");
        if (fromUrl == "hospitalRecords") {
            fromUrl = "hospitalRecords/hospitalRecords"
        }
        if(StringUtils.isEmpty(fromUrl)){
            fromUrl = '/html/HospitalService/inspention/searchReport.html';
        }
        $.QuickUrlUtils.redirectJSBridge({
            url: fromUrl
            , animate: "pop"
            ,refreshUrl: fromUrl
        });
    }


    var page_findHospital = (function($, page_findHospital) {


        /**加载视图*/
        function initView() {
            /**排序按钮*/
            $("#order").attr("value", "0");
            $("#order").on("click", function () {
                $(this).parents("li").siblings().find(".filtrate-sub-check").hide();
                $("#orderChildren").toggle();
                return false;
            });

            /**排序选中*/
            $("#orderChildren").on("click", "li", function () {
                if (!$(this).hasClass("active")) {
                    $(this).siblings("li").removeClass("active");
                    $(this).addClass("active");
                    $(this).parents(".filtrate-sub-check").hide();
                    var order = null;
                    var val = $(this).attr("value");
                    $("#order").attr("value", val).html($(this).find("a").html() + "<i class='iconfont icon-more'></i>")
                    /**获取行政区划*/
                    var xzqh = $("#xzqh").attr("value");
                    var params = {};
                    if (xzqh != "0") {
                        params["districtCode"] = xzqh;
                    }
                    if (val != "0") {
                        params["sortType"] = val;
                    }
                    page_findHospital.initHosInfo(params);
                }
            })

            // 点击document让当前的ul隐藏
            $(document).on("click", function () {
                $("#orderChildren").hide();
                $("#xzqhChildren").hide();
            })
            $("#orderChildren").on("click", function () {
                return false;
            });
            $("#xzqhChildren").on("click", function () {
                return false;
            });


            /**注册回调方法*/
            // $.JkcsUtils.jsbridgeRegister("search", callBack);
        }

        /**加载数据*/
        function initData() {

            /**加载医院信息*/
            var params = {};
            page_findHospital.initHosInfo(params);
        }

        /**加载医院信息*/
        function initHosInfo(params) {
            /**获取用户经纬度有延迟，需要回调获取*/
            if (params["sortType"] == "1") {
                params["mapType"] = "AMap";
                $.JkcsUtils.nativePermission({
                    "type": "location",
                    "callBackMethod": "page_findHospital.callBack",
                    "params": params
                });
//			params["userLocation"] = $.JkcsUtils.getUserLocation("callBack",params);

            } else {
                page_findHospital.callBack(params);
            }
        }

        function callBack(params) {
            //params["userLocation"] = params["longitude"]+","+params["latitude"];
            params["pageNum"] = 1;
            params["pageSize"] = 10;
            $("#hosUl").remove();
            var hosUl = $("<ul>").attr({"id": "hosUl"});
            $("#hosDiv").append(hosUl);
            layui.use('flow', function () {
                var flow = layui.flow;
                flow.load({
                    elem: '#hosUl' //指定列表容器
                    , end: " "
                    , done: function (page, next) { //到达临界点（默认滚动触发），触发下一页
                        params["pageNum"] = page;
                        page_findHospital.queryPageHos(params, page, next);
                    }
                });
            });
        }

        function queryPageHos(params, page, next){
            $.QuickRemote.AjaxJson({
                funcName: "/api" + requestRoot + "/getHospitalList"
                ,params: params
                ,callback: page_findHospital.hospitalListHandler
                ,additionParams:{next: next,page: page}
            });
        }

        function hospitalListHandler(result, obj) {
            //console.log(obj);
            var type = "";
            $("#orderChildren").find("li").each(function () {
                if ($(this).hasClass("active")) {
                    type = $(this).attr("value");
                    return;
                }
            });
            if (result["code"] == "0") {
                var pages = result["data"]["pageCount"];
                var ary = result["data"]["hospitals"];
                var lis = [];
                $(ary).each(function (index, item) {
                    var value = item["distance"];
                    if (value == "" || value == null) {
                        value = "0";
                    }
                    var hosLi = $($("#hosLi").html());
                    if (type != "1") {
                        $(hosLi).find(".distance").remove();
                    }
                    // $(hosLi).find(".hosImgUrl").attr("style","background:url('"+item["hosImgUrl"]+"') no-repeat;background-size: 100% 100%;");
                    $(hosLi).find(".hosName").text(item["hosName"]);
                    $(hosLi).find(".hosLevel").text(page_findHospital.getHosGrade(item["hosGrade"]) + page_findHospital.getHosLevel(item["hosLevel"]));//hosLevel
                    $(hosLi).find(".isMedicare").text(page_findHospital.getIsMedicare(item["isMedicare"]));
                    $(hosLi).find(".doctorCount").text(item["doctorCount"] + " 医生");
                    $(hosLi).find(".distance").text(value + "m");
                    var hosInfo = item;
                    hosInfo.hosDesc = "";
                    $(hosLi).find("a").attr("onclick", "toKslb('" + JSON.stringify(hosInfo) + "')");
                    lis.push($(hosLi).prop("outerHTML"));
                });
                obj.next(lis.join(''), obj.page < pages);
            } else {
                $.QuickAlert.alertFail({content: result["message"]});
            }
        }

        /**获取医院等级*/
        function getHosLevel(hosLevel) {
            var value = "";
            if (hosLevel == "0") {
                value = "特等";
            }
            else if (hosLevel == "1") {
                value = "甲等";
            }
            else if (hosLevel == "2") {
                value = "乙等";
            }
            else if (hosLevel == "3") {
                value = "丙等";
            }
            return value;
        }

        /**判断是否是医保*/
        function getIsMedicare(medicare) {
            var value = "";
            if (medicare == "0") {
                value = "医保";
            }
            else //if(medicare == "1")
            {
                value = "非医保";
            }
            return value;
        }

        /**获取医院级别*/
        function getHosGrade(hosGrade) {
            var value = "";
            if (hosGrade == "0") {
                value = "社区卫生服务中心";
            }
            else if (hosGrade == "1") {
                value = "一级";
            }
            else if (hosGrade == "2") {
                value = "二级";
            }
            else if (hosGrade == "3") {
                value = "三级";
            }
            else if (hosGrade == "") {
                value = "未评级";
            }
            return value;
        }

        function queryByCondition(obj) {

            $("#queryInput").blur();
            var params = {
                hosName: $("#queryInput").val(""),
                pageNum: '1',
                pageSize: '10'
            }
            var api = '';
            page_findHospital.initHosInfo(params, api);
        }
        var cfg_def = {
            initView: initView,
            initData: initData,
            initHosInfo: initHosInfo,
            callBack: callBack,
            queryPageHos: queryPageHos,
            hospitalListHandler: hospitalListHandler,
            getHosLevel: getHosLevel,
            getIsMedicare: getIsMedicare,
            getHosGrade: getHosGrade,
            queryByCondition: queryByCondition,
        }

        page_findHospital.init = function(cfg){
            $.extend(page_findHospital, cfg_def, cfg);
            page_findHospital.initData();
            page_findHospital.initView();
            $('form').submit(page_findHospital.queryByCondition)

        }

        return page_findHospital;
    })(jQuery, {});


</script>

</html>



